#include "wolf_states.h"
#include "Wolf.h"
#include "MessageTypes.h"
#include "Messaging/MessageDispatcher.h"
#include "Entity/EntityManager.h"
#include <iostream>
using namespace std;

void State_WolfRest::enter(Wolf* p_wolf) {
	cout << "WOLF: ENTER STATE-> Rest" << endl; 
}


void State_WolfRest::execute(Wolf* p_wolf) {
	cout << "WOLF: RESTing" << endl;
	p_wolf->m_energy = p_wolf->m_energy + 1;
}


void State_WolfRest::exit(Wolf* p_wolf) {
	cout << "WOLF: EXIT STATE-> Rest" << endl;
}


bool State_WolfRest::onMessage(Wolf* p_wolf, const Telegram& p_t) {
	cout << "WOLF HANDLING MESSSAGE IN REST STATE" << endl;

	if(p_t.message == MSG_BUNNY_StartResting) {
		p_wolf->m_stateMachine->changeState(new State_WolfChase);
	}

	return true;
}


//------------------------------------------------------------------------------
void State_WolfChase::enter(Wolf* p_wolf) {
	cout << "WOLF: ENTER STATE Chase" <<endl;
	MessageDispatcher::Instance()->dispatchMessage(
		0.25,
		p_wolf->getID(),
		id_bunny,
		MSG_WOLF_StartChasing,
		0);
}


void State_WolfChase::execute(Wolf* p_wolf) {
	cout << "WOLF Chasing" << endl;
	p_wolf->m_energy = p_wolf->m_energy - 3;
	if(p_wolf->m_energy < 10) {
		p_wolf->m_stateMachine->changeState(new State_WolfRest);
	}
}


void State_WolfChase::exit(Wolf* p_wolf) {
	cout << "WOLF: EXIT STATE Chase" << endl;
		MessageDispatcher::Instance()->dispatchMessage(
		0.25,
		p_wolf->getID(),
		id_bunny,
		MSG_WOLF_StopChasing,
		0);
}


bool State_WolfChase::onMessage(Wolf* p_wolf, const Telegram& p_t) {
	return true;
}

